<?php

// TITLE: committee
// FILE: committee.php
// AUTHOR: dantira
// CREATED: Mar 21, 2015, 4:51:14 PM
?>

		public function createCommittee($id, $title, $description) {
			global $con;
			$sql = 'INSERT INTO committee (id, title, description) VALUES (' . $id . ', ' . $title . ', ' . $description . ')';
			$this->open();
			$result = mysqli_query($con, $sql);
			$id = ($result) ? mysqli_insert_id($con) : $result;
			$this->close();
			return $id;
		}// end function

		public function readCommittee($id) {
			global $con;
			$sql = 'SELECT * FROM committee WHERE id = ' . $id;
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$result = mysqli_fetch_array($results);
				$committee = new Committee();
				$committee->setId($result[0]);
				$committee->setTitle($result[1]);
				$committee->setDescription($result[2]);
			} else {
				$committee = false;
			}
			return $committee;
		}// end function

		public function updateCommittee($id, $title, $description) {
			global $con;
			$sql = 'UPDATE committee SET title = ' . $title . ', description = ' . $description . ' WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function deleteCommittee($id) {
			global $con;
			$sql = 'DELETE FROM committee WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function listCommittee() {
			global $con;
			$sql = 'SELECT * FROM committee';
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$committees = array();
				while ($result = mysqli_fetch_array($results)) {
					$committee = new Committee();
					$committee->setId($result[0]);
					$committee->setTitle($result[1]);
					$committee->setDescription($result[2]);
					$committees[] = $committee;
				}// end while
			} else {
				$committees = false;
			}
			return $committees;
		}// end function

		// committee_attendance // --------------------

		public function createCommitteeAttendance($id, $committeeId, $volunteerId, $status, $date) {
			global $con;
			$sql = 'INSERT INTO committee_attendance (id, committee_id, volunteer_id, status, date) VALUES (' . $id . ', ' . $committeeId . ', ' . $volunteerId . ', ' . $status . ', ' . $date . ')';
			$this->open();
			$result = mysqli_query($con, $sql);
			$id = ($result) ? mysqli_insert_id($con) : $result;
			$this->close();
			return $id;
		}// end function

		public function readCommitteeAttendance($id) {
			global $con;
			$sql = 'SELECT * FROM committee_attendance WHERE id = ' . $id;
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$result = mysqli_fetch_array($results);
				$committeeAttendance = new CommitteeAttendance();
				$committeeAttendance->setId($result[0]);
				$committeeAttendance->setCommitteeId($this->readCommittee($result[1]));
				$committeeAttendance->setVolunteerId($this->readVolunteer($result[2]));
				$committeeAttendance->setStatus($result[3]);
				$committeeAttendance->setDate($result[4]);
			} else {
				$committeeAttendance = false;
			}
			return $committeeAttendance;
		}// end function

		public function updateCommitteeAttendance($id, $committeeId, $volunteerId, $status, $date) {
			global $con;
			$sql = 'UPDATE committee_attendance SET committee_id = ' . $committee_id . ', volunteer_id = ' . $volunteerId . ', status = ' . $status . ', date = ' . $date . ' WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function deleteCommitteeAttendance($id) {
			global $con;
			$sql = 'DELETE FROM committee_attendance WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function listCommitteeAttendance() {
			global $con;
			$sql = 'SELECT * FROM committee_attendance';
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$committeeAttendances = array();
				while ($result = mysqli_fetch_array($results)) {
					$committeeAttendance = new CommitteeAttendance();
					$committeeAttendance->setId($result[0]);
					$committeeAttendance->setCommitteeId($this->readCommittee($result[1]));
					$committeeAttendance->setVolunteerId($this->readVolunteer($result[2]));
					$committeeAttendance->setStatus($result[3]);
					$committeeAttendance->setDate($result[4]);
					$committeeAttendances[] = $committeeAttendance;
				}// end while
			} else {
				$committeeAttendances = false;
			}
			return $committeeAttendances;
		}// end function

